package com.MovieManageSystem.controller;

import com.MovieManageSystem.domain.Movie;
import com.MovieManageSystem.entity.Result;
import com.MovieManageSystem.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/movie")
@CrossOrigin(origins = "*")

public class MovieController {
    @Autowired
    private MovieService movieService;


// 根据id查询video
    @GetMapping("/{vid}")
    public Result getMovieByVid(@PathVariable Long vid){
        Movie movie = movieService.selectMovieByVid(vid);

        return Result.success(movie);

    }


    @GetMapping
    public Result getMovieList(Movie movie){
    List<Movie> deptList = movieService.getMovieList(movie);
    return Result.success(deptList);

    }

    /**
     * 新增影视
     */
    @PostMapping
    public Result add(@RequestBody Movie movie)
    {
        movieService.insertMovie(movie);
        return Result.success();

    }

    /**
     * 修改影视
     */
    @PutMapping
    public Result updateMovie(@RequestBody Movie movie)
    {
        movieService.updateMovie(movie);
        System.out.println(movie.toString());
        return Result.success();

    }

    /**
     * 删除影视
     */
    @DeleteMapping("/{vids}")
    public Result remove(@PathVariable Long[] vids)
    {
        movieService.deleteMovieByVids(vids);
        return Result.success();

    }
}




